﻿<UserControl x:Class="P_PersonalDetails.SlalomRanking"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:ref="clr-namespace:RefCodes;assembly=RefCodes"
             xmlns:local="clr-namespace:P_PersonalDetails"
    mc:Ignorable="d"
    d:DesignHeight="400" d:DesignWidth="400">

    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="FormStyling.xaml"/>
            </ResourceDictionary.MergedDictionaries>
            <local:DeleteSRCommand x:Key="DeleteCommand"/>
            
        </ResourceDictionary>
    </UserControl.Resources>
    <Border Style="{StaticResource BoxBorder}">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <TextBlock Style="{StaticResource BoxHeading}">
                <Run Text="Slalom Rankings at Start of"/>
                <Run Text="{Binding Year}"/>
                <Run Text="for"/>
                <Run Text="{Binding FullName}"/>
            </TextBlock>
            <Grid Grid.Row="1">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" MaxWidth="50"/>
                    <ColumnDefinition Width="2*" MaxWidth="100"/>
                    <ColumnDefinition Width="2*" MaxWidth="100" />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <TextBlock Grid.Column="0" Text="Class"/>
                <TextBlock Grid.Column="1" Text="Division"/>
                <TextBlock Grid.Column="2" Text="Bib"/>
                <ItemsControl Grid.Row="1" Grid.ColumnSpan="3" ItemsSource="{Binding SingleDivisions}">
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <Grid Grid.Row="1">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*" MaxWidth="50"/>
                                    <ColumnDefinition Width="2*" MaxWidth="100"/>
                                    <ColumnDefinition Width="2*" MaxWidth="100" />
                                </Grid.ColumnDefinitions>
                                <TextBlock Grid.Column="0" Text="{Binding ClassName}"/>
                                <ref:RefCodesComboBox Grid.Column="1" L2RefCode="{Binding ClassRC, Mode=OneWay}" SelectedID="{Binding DivisionRCL2, Mode=TwoWay, ValidatesOnExceptions=True}"/>
                                <TextBox Grid.Column="2" Text="{Binding BibNumber, Mode=TwoWay, ValidatesOnExceptions=True, TargetNullValue=''}"/>
                            </Grid>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
            </Grid>
            <Grid Grid.Row="2" x:Name="HasPartnerGrid">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" MaxWidth="70"  MinWidth="45"/>
                    <ColumnDefinition Width="4*" MaxWidth="200"/>
                    <ColumnDefinition Width="2*" MaxWidth="100"/>
                    <ColumnDefinition Width="2*" MaxWidth="100" />
                    <ColumnDefinition Width="60"/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <TextBlock Grid.Column="0" Text="Class"/>
                <TextBlock Grid.Column="1" Text="Partner"/>
                <TextBlock Grid.Column="2" Text="Division"/>
                <TextBlock Grid.Column="3" Text="Bib"/>
                <TextBlock Grid.Column="4" Text="Delete"/>
                <ItemsControl Grid.Row="1" Grid.ColumnSpan="5" ItemsSource="{Binding DoubleDivisions}">
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <Grid Grid.Row="1">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*" MaxWidth="70"  MinWidth="45"/>
                                    <ColumnDefinition Width="4*" MaxWidth="200"/>
                                    <ColumnDefinition Width="2*" MaxWidth="100"/>
                                    <ColumnDefinition Width="2*" MaxWidth="100" />
                                    <ColumnDefinition Width="60"/>
                                </Grid.ColumnDefinitions>
                                <TextBlock Grid.Column="0" Text="{Binding ClassName}"/>
                                <ref:RefCodesComboBox CodeType="6" SelectedID="{Binding ClassRC, Mode=TwoWay, ValidatesOnExceptions=True}"/>
                                <local:PartnerAutoComplete  Grid.Column="1" SelectedID="{Binding PartnerID, Mode=TwoWay, ValidatesOnExceptions=True}"
                                                            SelectedName="{Binding PartnerName, Mode=TwoWay, ValidatesOnExceptions=True}"/>
                                <ref:RefCodesComboBox Grid.Column="2" L2RefCode="{Binding ClassRC, Mode=OneWay}" SelectedID="{Binding DivisionRCL2, Mode=TwoWay, ValidatesOnExceptions=True}"/>
                                <TextBox Grid.Column="3" Text="{Binding BibNumber, Mode=TwoWay, ValidatesOnExceptions=True, TargetNullValue=''}"/>
                                <Button Grid.Column="4" Style="{StaticResource Delete}" Command="{StaticResource DeleteCommand}" CommandParameter="{Binding ID}" />
                            </Grid>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
            </Grid>
            <Button Grid.Row="4" Click="AddDoubleDivision" HorizontalAlignment="Left">Add Ranking</Button>
        </Grid>
    </Border>
</UserControl>
